/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.admin.message.AddGalSyncDataSourceRequest;
/*     */ import com.zimbra.soap.admin.type.GalMode;
/*     */ import com.zimbra.soap.type.AccountBy;
/*     */ import com.zimbra.soap.type.AccountSelector;
/*     */ import java.util.Collections;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class AddGalSyncDataSource
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public boolean domainAuthSufficient(Map<String, Object> context)
/*     */   {
/*  46 */     return true;
/*     */   }
/*     */   
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  52 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*  53 */     Provisioning prov = Provisioning.getInstance();
/*     */     
/*  55 */     AddGalSyncDataSourceRequest dsRequest = (AddGalSyncDataSourceRequest)JaxbUtil.elementToJaxb(request);
/*     */     
/*  57 */     String name = dsRequest.getName();
/*  58 */     String domainStr = dsRequest.getDomain();
/*  59 */     GalMode type = dsRequest.getType();
/*     */     
/*  61 */     AccountSelector acctSelector = dsRequest.getAccount();
/*  62 */     AccountBy acctBy = acctSelector.getBy();
/*  63 */     String acctValue = acctSelector.getKey();
/*  64 */     String folder = dsRequest.getFolder();
/*     */     
/*  66 */     Domain domain = prov.getDomainByName(domainStr);
/*     */     
/*  68 */     if (domain == null) {
/*  69 */       throw AccountServiceException.NO_SUCH_DOMAIN(domainStr);
/*     */     }
/*     */     
/*  72 */     Account account = null;
/*     */     try {
/*  74 */       account = prov.get(acctBy.toKeyAccountBy(), acctValue, zsc.getAuthToken());
/*     */     } catch (ServiceException se) {
/*  76 */       ZimbraLog.gal.warn("error checking GalSyncAccount", se);
/*     */     }
/*     */     
/*  79 */     if (account == null) {
/*  80 */       throw AccountServiceException.NO_SUCH_ACCOUNT(acctValue);
/*     */     }
/*     */     
/*  83 */     if (!Provisioning.onLocalServer(account)) {
/*  84 */       String host = account.getMailHost();
/*  85 */       Server server = prov.getServerByName(host);
/*  86 */       return proxyRequest(request, context, server);
/*     */     }
/*     */     
/*  89 */     CreateGalSyncAccount.addDataSource(request, zsc, account, domain, folder, name, type);
/*     */     
/*  91 */     Element response = zsc.createElement(AdminConstants.ADD_GAL_SYNC_DATASOURCE_RESPONSE);
/*  92 */     ToXML.encodeAccount(response, account, false, emptySet, null);
/*  93 */     return response;
/*     */   }
/*     */   
/*  96 */   private static final Set<String> emptySet = ;
/*     */   
/*     */ 
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 101 */     relatedRights.add(Rights.Admin.R_createAccount);
/* 102 */     notes.add(String.format("All attrs provided in the attribute list have to settable by. the authed admin.   You can grant the %s right, which allows setting all attributes on %s, or grant the set attrs right just for the attributes the admin needs to set while creating an entry.", new Object[] { Rights.Admin.R_modifyAccount.getName(), "account" }));
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/AddGalSyncDataSource.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */